/*
 * ﻿Copyright (C) 2009-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.gwetons.client;

import java.util.LinkedHashSet;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.HeadElement;
import com.google.gwt.dom.client.MetaElement;
import com.google.gwt.junit.client.GWTTestCase;

/**
 * GWT JUnit tests must extend GWTTestCase.
 */
public class GwtTest_MetaTagCrawler extends GWTTestCase {

  /**
   * Must refer to a valid module that sources this class.
   */
  public String getModuleName() {
    return "com.newmainsoftech.gwetons.GWeTons";
  }

  /**
   * Add as many tests as you like.
   */
  public void testGetContents() {
	  HeadElement headElement = HeadElement.as( Document.get().getElementsByTagName( "head").getItem( 0));
	  assertNotNull( headElement);
	  
	  String metaContent0 = "bncabsbGALoad=false";
	  MetaElement metaElement = Document.get().createMetaElement();
	  metaElement.setName( "gwt:property");
	  metaElement.setContent( metaContent0);
	  headElement.appendChild( metaElement);
	  
	  String metaContent1 = "bncabsbWrapperId=baWrapper";
	  metaElement = Document.get().createMetaElement();
	  metaElement.setName( "gwt:property");
	  metaElement.setContent( "bncabsbWrapperId=baWrapper");
	  headElement.appendChild( metaElement);
	  
	  String metaContent2 = "bncabsbSite=en.wikipedia.org";
	  metaElement = Document.get().createMetaElement();
	  metaElement.setName( "gwt:property");
	  metaElement.setContent( "bncabsbSite=en.wikipedia.org");
	  headElement.appendChild( metaElement);
	  
	  String metaContent3 = "bncabsbSite=en.wikipedia.org";
	  metaElement = Document.get().createMetaElement();
	  metaElement.setName( "gwt:property");
	  metaElement.setContent( "bncabsbSite=en.wikipedia.org");
	  headElement.appendChild( metaElement);
	  
	  LinkedHashSet<String> gwtPropertyLinkedHashSet = MetaTagCrawler.getContents("gwt:property");
	  String[] metaContentArray = gwtPropertyLinkedHashSet.toArray( new String[ 0]);
	  for( int metaContentIndex = 0; metaContentIndex < metaContentArray.length; metaContentIndex++) {
		  switch( metaContentIndex) {
			  case 0:
				  assertEquals( metaContent0, metaContentArray[ metaContentIndex]);
				  break;
			  case 1:
				  assertEquals( metaContent1, metaContentArray[ metaContentIndex]);
				  break;
			  case 2:
				  assertEquals( metaContent2, metaContentArray[ metaContentIndex]);
				  break;
			  case 3:
				  assertEquals( metaContent3, metaContentArray[ metaContentIndex]);
				  break;
			  default:
				  assertEquals( 4, gwtPropertyLinkedHashSet.size());
				  break;
		  } // switch
	  } // for
  }

}
